package com.dubboService.way2;

import com.base.UserService;
import com.base.UserServiceImpl;
import org.apache.dubbo.config.*;

import java.io.IOException;

public class DubboProvider2 {
    public static void main(String[] args) throws IOException {
        UserServiceImpl userService = new UserServiceImpl();
        // 当前应用配置
        ApplicationConfig application = new ApplicationConfig();
        application.setName("hello-world-app");

        // 连接注册中心配置
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("zookeeper://127.0.0.1:2181");

        // 服务提供者暴露服务配置
        ServiceConfig<UserService> service = new ServiceConfig<>();
        service.setApplication(application);
        service.setRegistry(registry); // 多个注册中心可以用setRegistries()
        service.setInterface(UserService.class);
        service.setRef(userService);
        service.setVersion("1.0.0");

        // 暴露及注册服务
        service.export();
        System.out.println("已经发现");
        System.in.read(); // 按任意键退出
    }
}
